﻿// -----------------------------------------------------------------------
// <copyright file="Generate.cs" company="Microsoft">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

namespace AwesomeUtils
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Security.Cryptography;

    /// <summary>
    /// TODO: Update summary.
    /// </summary>
    public class Generate
    {

        public static string GenerateRandomKey
        {
            get
            {
                return Guid.NewGuid().ToString().Replace("-", "").Replace(" ", "").Replace("{", "").Replace("}", "");
            }
        }

        private static string GenerateKey(int maxSize, int minSize = 0)
        {
            int size = maxSize;
            if (minSize > 0 && minSize < maxSize)
            {
                Random rnd = new Random();
                size = rnd.Next(minSize, maxSize);
            }
            //todo: put in randomizer between min and max
            char[] chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890".ToCharArray();
            byte[] data = new byte[1];
            RNGCryptoServiceProvider crypto = new RNGCryptoServiceProvider();
            crypto.GetNonZeroBytes(data);
            data = new byte[size];
            crypto.GetNonZeroBytes(data);
            StringBuilder result = new StringBuilder(size);
            foreach (byte b in data)
            {
                result.Append(chars[b % chars.Length]);
            }
            return result.ToString();
        }




    }
}
